package mx.ags.miforo.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mx.ags.miforo.business.LoginBusiness;

public class LoginServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6938409155001341774L;
	private LoginBusiness  loginBusiness = new LoginBusiness();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("ENTRO GET");
		String user = (String) req.getParameter("user");
		String password = (String) req.getAttribute("password");
		try {
			loginBusiness.login(user, password);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				PrintWriter out = resp.getWriter();
		
		 out.println("<html>");
	        out.println("<head>");

	        String title = "hola mundo";

	        out.println("<title>" + title + "</title>");
	        out.println("</head>");
	        out.println("<body bgcolor=\"white\">");

	        // note that all links are created to be relative. this
	        // ensures that we can move the web application that this
	        // servlet belongs to to a different place in the url
	        // tree and not have any harmful side effects.

	        // XXX
	        // making these absolute till we work out the
	        // addition of a PathInfo issue

	        out.println("<a href=\"../helloworld.html\">");
	        out.println("<img src=\"../images/code.gif\" height=24 " +
	                    "width=24 align=right border=0 alt=\"view code\"></a>");
	        out.println("<a href=\"../index.html\">");
	        out.println("<img src=\"../images/return.gif\" height=24 " +
	                    "width=24 align=right border=0 alt=\"return\"></a>");
	        out.println("<h1>" + title + "</h1>");
	        out.println("</body>");
	        out.println("</html>");
	        
	        resp.sendRedirect("home.jsp");
		//super.doGet(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("ENTRO POST");
		this.doGet(req, resp);
		//super.doPost(req, resp);
	}
	
	/*@Override
	protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		System.out.println("ENTRO SERVICE");
		//super.service(arg0, arg1);
	}
*/
}
